// 1.引入type User
import { ref } from 'vue';
import type { User } from '../../types/user';
// 2.引入defineStore
import { defineStore } from 'pinia';
// 3.抛出
export const useUserStore = defineStore(
  'cp-user',
  () => {
    const user = ref<User | null>(null);
    // 设置用户
    const setUser = (u: User) => {
      user.value = u;
    };
    //清空用户 退出时使用
    const delUser = () => {
      user.value = null;
    };
    return { user, setUser, delUser };
  },
  {
    persist: true
  }
);
